<?php
/**
 * Created by IntelliJ IDEA.
 * User: andyhuang
 * Date: 2018/3/18
 * Time: 11:38
 */
require_once("./ActionResult.php");
require_once("./UserInfo.php");
session_start();

header("charset=utf-8");

$openid = '';
//$redirect_url = 'http://huangww.tunnel.echomod.cn/mdl/src/recommend.php';

if(isset($_GET['path'])) {
    $redirect_url = $_GET['path'];
    //var_dump($redirect_url);
}

if (isset($_SESSION["mdl_userid"])) {
    $openid = $_SESSION["mdl_userid"];
    //var_dump($openid);
}

//var_dump($_SESSION["mdl_userid"]);

if(!empty($openid)) {
    //  get the data and  return
    // $openid = '0001';
    $value = getProductsByOpenid($openid);
    //$value = "it is test value";
    $response = new ActionResult(0,'success', $value);
    echo $response->getJsonBody();
}else{
    $value = array( 'redirect' => "WechatCtrl.php?path=".urlencode($redirect_url));
    $response = new ActionResult(1,'no openid', $value);
    echo $response->getJsonBody();
    //echo $_SERVER['HTTP_HOST'].$_SERVER['PATH_TRANSLATED']."/model/WechatCtrl.php?path=".urlencode($redirect_url);
   // header("Location: ./model/WechatCtrl.php?userUrl=".urlencode($redirect_url));
}
exit;

